<?php

/**
 * baseField : Mother of all field class. Contains field core informations
 *
 * @package
 * @author Alexis Eric
 * @copyright Copyright (c) 2012 - Erra Prod
 * @version $1.0$
 * @access public
 */
class Erra_Fields_Base_BaseField {

    protected $_objectId = null;
    protected $_name = null;
    protected $_rawData = null;
    protected $_databaseType = array('none');
    protected $_defaultValue = null;
    protected $_tableName = null;
    protected $_bSynchronized = true;

    public function __construct($objectId = null) {
        $this->_objectId = $objectId;
        $this->_name = $objectId;
    }

    public function isNull() {
        return is_null($this->_rawData);
    }

    /** Getters and setters  */
    public function getObjectId() {
        return $this->_objectId;
    }

    public function setObjectId($objectId) {
        $this->_objectId = $objectId;
        return $this;
    }

    public function setName($value) {
        $this->_name = $value;
        return $this;
    }

    public function getName() {
        return $this->_name;
    }

    public function getDatabaseTypeString() {
        $databaseString = (isset($this->_databaseType[1]) && is_numeric($this->_databaseType[1]) && $this->_databaseType[1] > 0) ? $this->_databaseType[0] . '(' . $this->_databaseType[1] . ')' : $this->_databaseType[0];
        return strtoupper($databaseString);
    }

    public function setDatabaseType($type, $size=null) {
        $databaseType = (!is_null($size) && is_numeric($size)) ? array($type, $size) : array($type);
        $this->_databaseType = $databaseType;
        return $this;
    }

    public function getDatabaseType() {
        return $this->_databaseType;
    }

    public function setDefaultValue($defaultValue) {
        $this->_defaultValue = $defaultValue;
        $this->setValue($defaultValue);
        return $this;
    }

    public function getDefaultValue() {
        return $this->_defaultValue;
    }
    
    public function setTableName($tableName) {
        $this->_tableName = $tableName;
        return $this;
    }

    public function getTableName() {
        if($this->_tableName != null) {
            return strtolower($this->_tableName);
        }
        return strtolower(get_class($this));
    }
    
    
    public function isSynchronized() {
        return $this->_bSynchronized;
    }

    public function setSynchronized($bSynchronized) {
        $this->_bSynchronized = $bSynchronized;
        return $this;
    }

}

?>